public class Timer extends Thread
{

	private IntController hint;
	private int counter;
	private int slice;
	public Timer(IntController i)
	{
		hint = i;
		counter = 0;
		slice = 2;
 	}
	
// For the services below, time is expressed in tenths of seconds
public void setSlice(int t) { slice = t; } 
public void setTime(int t) { counter = t; } 
public int getTime() { return counter; }

// This is the thread that keeps track of time and generates the
// interrupt when a slice has ended, but can be reset any time
// with any "time-to-alarm"
	public void run()
	{
		while (true)
		{
		    counter = slice;
		    while (counter > 0)
			{
		      try { sleep(150); }
		      catch (InterruptedException e){}
				--counter;
				System.err.println("TICK "+counter);
			  }
		    //System.err.println("timer INT");
		    hint.set(2);
		    hint.set(2); //because we have to consumers aka 2 CPUs
		}
	}
}